home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / MEMLib.lha / MEMLib / Developer / source / mempriv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-30  |  5.6 KB  |  140 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989, 1990, 1991 The Software Distillery.        *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by Doug Walker                               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           405 B3 Gooseneck Drive                               *
  7. * ======             Cary, NC 27513                                       *
  8. *                                                                         *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10.  
  11. /**************************************************************************/
  12. /**************************************************************************/
  13. /**************************************************************************/
  14. /*                                                                        */
  15. /* DO NOT INCLUDE THIS FILE IN YOUR PROGRAM.  IT IS FOR MEMLIB'S INTERNAL */
  16. /* USE ONLY.  USE THE FILE "memwatch.h" FOR YOUR PROGRAM FILES.           */
  17. /*                                                                        */
  18. /**************************************************************************/
  19. /**************************************************************************/
  20. /**************************************************************************/
  21.  
  22. #ifndef D_MEMPRIV_H
  23. #define D_MEMPRIV_H
  24.  
  25.  
  26. #include <exec/types.h>
  27. #include <exec/memory.h>
  28. #include <exec/ports.h>
  29. #include <proto/exec.h>
  30. #include <proto/dos.h>
  31. #include <string.h>
  32. #include <stdarg.h>
  33.  
  34. #define MWDEBUG 1   /* MWDEBUG is always defined for the library itself */
  35. #include "memwatch.h"
  36.  
  37. #define MW_NEWLINE "\n"    /* echo a newline before each error */
  38.                            /* note that this was defined as "\7\n" in the original */
  39.  
  40. #ifdef AllocMem
  41. #undef AllocMem
  42. #endif
  43.  
  44. #ifdef FreeMem
  45. #undef FreeMem
  46. #endif
  47.  
  48. #define MWT_CHIP 0
  49. #define MWT_FAST 1
  50.  
  51. #define MW_HEADLEN  4  /* Number of bytes for header sentinel */
  52.  
  53. /* The following string must be >= MW_HEADLEN bytes */
  54. #define MWHEADSTR "HEAD"
  55.                  /*0123*/
  56.  
  57. #define MW_TRAILLEN 8  /* Number of bytes for trailer sentinel */
  58.  
  59. /* The following string must be >= MW_TRAILLEN bytes */
  60. #define MWTRAILSTR "\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB"
  61.  
  62. struct MWGlobal
  63. {
  64.    LONG flags;          /* Various MWF_ flags, see memwatch.h           */
  65.    LONG num[2];         /* Current number of allocations, chip and fast */
  66.    LONG sum[2];         /* Current amount allocated, chip and fast      */
  67.    LONG max[2];         /* Max amount allocated, chip and fast          */
  68.    LONG lim[2];         /* Limit on allocations, chip and fast          */
  69.    BPTR dbfh;           /* File to send debug output to                 */
  70.    struct MWAlc *first; /* List of active memory allocations            */
  71.    struct MWAlc *freed; /* List of free memory extents                  */
  72.    struct MWAlc *lfree; /* Last allocation freed with free()            */
  73.    struct Task *task;   /* Pointer to owning task's Task structure      */
  74.    char *dbnm;          /* name of debug log file                       */
  75.    int headlen,         /* Length of header sentinel                    */
  76.        traillen;        /* Length of trailer sentinel                   */
  77. };
  78.  
  79. struct MWAlc
  80. {
  81.    struct MWAlc *next;  /* Next memory block in chain           */
  82.    LONG size;           /* Size of allocation in bytes          */
  83.    LONG flags;          /* MEMF_ Flags memory was allocated with*/
  84.    LONG internal;       /* internal flags, see MWI_ defines     */
  85.    char *file;          /* Filename containing allocation point */
  86.    LONG line;           /* Line number of allocation            */
  87.    char *ffile;         /* Filename of free point               */
  88.    long fline;         /* Line number of free point            */
  89.    char header[MW_HEADLEN];     /* Header sentinal              */
  90.    char memory[MW_TRAILLEN+3];  /* Actual allocation comes here */
  91.                         /* extra bytes cover trailer sentinal   */
  92. };
  93.  
  94. /* Defines for use with MWAlc.internal       */
  95. /* if internal&MWI_REPMASK == MWI_REPORTED,  */
  96. /* This alloc already reported as trashed    */
  97. /* Use multiple bits in case 'internal'      */
  98. /* are trashed, odds are better of detecting */
  99. /* If we ever need more myflag bits, just    */
  100. /* define MWI_REPMASK not to include them    */
  101.  
  102. #define MWI_REPORTED 0xaa55aa50
  103. #define MWI_REPMASK  0xfffffff0
  104.  
  105.  
  106. #define MWATRASH     0xaa  /* Trash allocated memory with this           */
  107. #define MWFTRASH     0x55  /* Trash freed memory with this               */
  108.  
  109. void MWHold   (void);
  110. void MWPurge  (void);
  111. void MWPanic  (char *);
  112. void MWPrintf (char *, ...);
  113. int MWCheckA  (struct MWAlc *);
  114.  
  115. /* If you want debugging to use the serial port, you must have */
  116. /* Commodore's debug.lib.  If you do, change the #define below */
  117. /* to a 1 and add debug.lib to your link line.                 */
  118. #define USEDEBUGLIB 0
  119. #if USEDEBUGLIB
  120. /* Defined in Commodore's debug.lib */
  121. void __stdargs KPutStr(char *string);
  122. #else
  123. #define KPutStr(x)
  124. #endif
  125.  
  126. #define MWPrintAlc(mwa) \
  127.    {MWPrintf("0x%08lx length %ld allocated line %ld file \"%s\"\n", \
  128.             (mwa)->memory, (mwa)->size, (mwa)->line, (mwa)->file); \
  129.     if((mwa)->ffile) MWPrintf("Freed line %ld file \"%s\"\n", \
  130.        (mwa)->fline, (mwa)->ffile);}
  131.  
  132. #define ALCFAMILY(x) ((x) & MWI_MALLOC ? "malloc"    : \
  133.                       (x) & MWI_VEC    ? "AllocVec"  : "AllocMem")
  134.  
  135. #define FREFAMILY(x) ((x) & MWI_MALLOC ? "free"     : \
  136.                       (x) & MWI_VEC    ? "FreeVec"  : "FreeMem")
  137.  
  138. #endif /* D_MEMPRIV_H */
  139.  
  140.